<!DOCTYPE html>
<html>
<head>
<?php include_once VIEWS.'inc/head.php'; ?>
</head>

<body  class="loginbg">
    <div class="loginbox">
    	<div class="login-tit f-cb bb">
    		<a href="javascript:;" class="cur normal">普通登录<i></i></a>
    		<a href="javascript:;" class="code">手机动态码登录<i></i></a>
    	</div>
    	<div class="login-normal-box db">
			<div class="login-input-box">
				<div class="login-line bb">
					<input type="text" class="login-input" name="phone" id="phone" placeholder="手机号码" maxlength="11">
				</div>
				<div class="login-line">
					<input type="password" class="login-input" name="pwd" id="pwd" placeholder="密码">
				</div>
			</div>
			<input type="button" class="login-sub" name="" id="no_smscode" value="登录">
    	</div>
    	<div class="login-normal-box">
			<div class="login-input-box">
				<div class="login-line bb">
					<input type="text" class="login-input" name="phone" id="phone_smscode" placeholder="手机号码" maxlength="11">
				</div>
				<div class="login-line bb f-cb">
					<input type="text" class="login-input half fl" name="captchas" id="captchas" placeholder="右侧图形验证码" maxlength="4">
					<img src="<?php echo site_url('captchas') ?>" class="fr code-img" width="94" height="36" style="cursor:pointer">
				</div>
				<div class="login-line f-cb">
					<input type="text" class="login-input half fl" name="smscode" id="smscode" placeholder="动态验证码" maxlength="6">
					<div class="get-code fr" id="get_code">获取验证码</div>
				</div>
			</div>
			<input type="button" class="login-sub" name="" id="have_smscode" value="登录">

    	</div>
    </div>
<?php
	echo static_file('web/js/main.js');
?>
<script>
$(function(){
	$("img.code-img").click(function() {
		$(this).attr('src',SITE_URL+'/captchas?t='+Math.random()*10);
	});
	var h = $(window).height();
	var w = $(window).width();
	$('.loginbg').css({
		width:w+'px',
		height:h+'px'
	});

	$('.login-tit a').on('click',function(){
		var index = $(this).index();
		$(this).addClass('cur').siblings().removeClass('cur');
		$('.login-normal-box').eq(index).addClass('db').siblings().removeClass('db');
	});
	$('#no_smscode').click(function() {
		var phone = $('#phone').val();
		var pwd = $('#pwd').val();
		var url = '<?php echo site_url('/login/go/')?>';
		if(!phone) {
			alert('请填写手机号');
			return false;
		}
		if(!phone.match( /^1[3-9]{1}[0-9]{9}$/ )) {
			alert('手机格式不对，请重新输入');
			return false;
		}
		if(!pwd) {
			alert('请填写密码');
			return false;
		}
		$.ajax({
			url:url,
			type:'post',
			dataType:'json',
			data:{phone:phone,pwd:pwd,type:'reg',_scfs: $.cookie('_scfc')}
		}).done(function(data){
			if(data.status == 1) {
				window.location.href='<?php echo site_url('/article')?>';
			} else {
				var i=0;
				$.each(data.msg,function(putid,putv){
					i++;
					if(i==1){ alert(putv); }
				});
			}
		})

	});
	$('#have_smscode').click(function() {
		var phone = $('#phone_smscode').val();
		var captchas = $('#captchas').val();
		var smscode = $('#smscode').val();
		var url = '<?php echo site_url('/login/haveCode/')?>';
		if(!phone) {
			alert('请填写手机号');
			return false;
		}
		if(!phone.match( /^1[3-9]{1}[0-9]{9}$/ )) {
			alert('手机格式不对，请重新输入');
			return false;
		}
		if(!captchas) {
			alert('请输入图形验证码');
			return false;
		}
		if(!smscode) {
			alert('请输入手机验证码');
			return false;
		}
		$.ajax({
			url:url,
			type:'post',
			dataType:'json',
			data:{phone:phone,captchas:captchas,code:smscode,_scfs: $.cookie('_scfc')}
		}).done(function(data){
			if(data.status == 1) {
				window.location.href='<?php echo site_url('/article')?>';
			} else {
				var i=0;
				$.each(data.msg,function(putid,putv){
					i++;
					if(i==1){ alert(putv); }
				});
			}
		})
	});
	$('#get_code').click(function() {
		if($('#get_code').hasClass('on')){
			return;
		}
		var time = 60;
		var phone = $('#phone_smscode').val();
		var captchas = $('#captchas').val();
		var url = '<?php echo site_url('/login/getPhoneCode/')?>';
		if(!phone) {
			alert('请填写手机号');
			return false;
		}
		if(!phone.match( /^1[3-9]{1}[0-9]{9}$/ )) {
			alert('手机格式不对，请重新输入');
			return false;
		}
		if(!captchas) {
			alert('请输入图形验证码');
			return false;
		}
		$.ajax({
			url:url,
			type:'post',
			dataType:'json',
			data:{phone:phone,captchas:captchas,_scfs: $.cookie('_scfc')}
		}).done(function(data){
			if(data.status == 1) {
				alert(data.msg);
				$('#get_code').addClass('on');
				var cutdown = setInterval(function(){
					time--;
					$('#get_code').html(time+'s再次发送');
					if(time == 0){
						clearInterval(cutdown);
						$('#get_code').html('获取验证码');
						$('#get_code').removeClass('on');
					}
				},1000)
			} else {
				var i=0;
				$.each(data.msg,function(putid,putv){
					i++;
					if(i==1){ alert(putv); }
				});
			}
		})
	});
})
</script>
</body>
</html>